package com.wssnail.xss.service.impl;

import com.wssnail.xss.mapper.UserMapper;
import com.wssnail.xss.model.User;
import com.wssnail.xss.service.UserService;
import com.wssnail.xss.utils.StringEscapeCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: yan
 * @CreateTime: 2023-08-11 14:55
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void saveUser(User user) {
        userMapper.save(user);
    }

    @Override
    public User getById(Integer id) {
        try {
            User user = userMapper.findByID(id);
            Class<? extends User> clazz = user.getClass();
            StringEscapeCodeUtil.unStringEscape(clazz, user);
            return user;
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
